package com.foreverwin.jzymes.report.pack.service.impl;

import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.production.debur.domain.PackLog;
import com.foreverwin.jzymes.report.pack.mapper.PackingReportMapper;
import com.foreverwin.jzymes.report.pack.service.IPackingReportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class PackingReportServiceImpl implements IPackingReportService {
    @Autowired
    PackingReportMapper packingReportMapper;

    @Override
    public List<PackLog> findpackingSearch(Map<String, Object> jsonMap) {
        String itemBo = (String)jsonMap.get("itemBo");
        String site = CommonMethods.getSite();
        Date startDate = null;
        Date endDate = null ;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        if ( !StringUtils.isEmpty( (String) jsonMap.get( "startDate" ) )){
            try {
                startDate = sdf.parse( (String) jsonMap.get( "startDate" ) );
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        if (  !StringUtils.isEmpty( (String) jsonMap.get( "startDate" ) ) ){
            try {
                endDate = sdf.parse( (String) jsonMap.get( "endDate" ) );
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        List<PackLog> packLogs = packingReportMapper.findpackingSearch( site,itemBo,startDate, endDate );


        return packLogs;
    }
}

